package com.zeildx.glife;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Adapter extends RecyclerView.Adapter <Adapter.MyViewHolder>{
    List<Event> allEvents = new ArrayList<>();

    public void setAllEvents(List<Event> allEvents) {
        this.allEvents = allEvents;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View itemView = layoutInflater.inflate(R.layout.event_normal,parent,false);
        return new MyViewHolder(itemView);
        //return null;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Event event = allEvents.get(position);
        holder.textViewEvent.setText(event.getEvent());
        holder.textView_Number.setText(String.valueOf(position + 1));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Uri uri = Uri.parse(http://www.c4best.cn/);
            }
        });
    }

    @Override
    public int getItemCount() {
        return allEvents.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textViewEvent,textView_Number;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            textViewEvent = itemView.findViewById(R.id.textViewEvent);
            textView_Number = itemView.findViewById(R.id.textView_Number);
        }
    }
}
